
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>出入园区人员信息管理</title>

<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.6.7/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.6.7/themes/icon.css">
<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.6.7/demo/demo.css">
<script type="text/javascript" src="/js/jquery-easyui-1.6.7/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-easyui-1.6.7/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/jquery-easyui-1.6.7/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/js/func.js"></script>

<script type="text/javascript">

	function searchReader()
	{

		$('#dg').datagrid('load',
		{
			rowid:$('#s_rowId').val(),
//			readerId:$('#s_readerId').val(),
//			departmentName:$('#s_departmentName').val()
		});
	}
		
	function deleteReader()
	{
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length==0)
		{
			$.messager.alert("系统提示","请选择要删除的数据！");
			return;
		}
		var strIds=[];
		for(var i=0;i<selectedRows.length;i++)
		{
			strIds.push(selectedRows[i].rowid);
		}
		
		var ids=strIds.join(",");
		
		$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r)
		{
			if(r)
			{
				$.post("../class/readerDelete.php",{delIds:ids},function(result)
				{
					if(result.success){
						$.messager.alert("系统提示","您已成功删除<font color=red>"+result.delNums+"</font>条数据！");
						$("#dg").datagrid("reload");
					}else{
						$.messager.alert('系统提示',result.errorMsg);
					}
				},"json");
			}
		});
	}

	function openReaderAddDialog()
	{
		$("#dlg").dialog("open").dialog("setTitle","添加人员信息");
		$("#rowidtr").hide();
		url="/class/readerSave.php";
	}
	
	function openReaderQietuDialog()
	{
		$("#dlgqt").dialog("open").dialog("setTitle","添加人员切图");
		//url="/class/readerSave.php";
	}

	function openReaderModifyDialog()
	{
		var selectedRows=$("#dg").datagrid('getSelections');
		if(selectedRows.length!=1){
			$.messager.alert("系统提示","请选择一条要编辑的数据！");
			return;
		}
		var row=selectedRows[0];
		
		$("#dlg").dialog("open").dialog("setTitle","编辑人员信息");
		$("#fm").form("load", row);
		
//		$("#rowidtr").style.display="block";
//		$("#rowidtr").style.visibility="visible";
		$("#rowidtr").show();

		url="/class/readerSave.php";	
	}
	
	function closeReaderDialog()
	{
		$("#dlg").dialog("close");
		resetValue();
	}
	
	function resetValue(){
		$("#readername").val("");
		$("#readerid").val("");
		$("#cardid").val("");
		$("#imagefile").val("");	
	}
	
	function jianchageshi()
	{
		if(!isAllNum($('#staffnum').val()))
	    {
	        $.messager.alert("系统提示",'编号只能是数字，请重新输入。');
	        return false;
	    }
	    if(!isAllEngAndChAndNum($('#staffname').val()))
	    {
	        $.messager.alert("系统提示",'姓名只能是中文、字母和数字，请重新输入。');
	        return false;
	    }
	    if(isRealLength($('#staffname').val())>64)
   		{
   			$.messager.alert("系统提示",'姓名太长，请重新输入。');
	        return false;
   		}
   		if(!isAllEngAndNum($('#cardnum').val()))
    	{
    		$.messager.alert("系统提示",'卡号只能是字母和数字，请重新输入。');
	        return false;
    	}
    	if(!isAllEngAndChAndNum($('#departmentname').val()))
    	{
    		$.messager.alert("系统提示",'部门名称只能是中文、字母和数字，请重新输入。');
	        return false;
    	}
    	if(isRealLength($('#departmentname').val())>64)
    	{
   			$.messager.alert("系统提示",'部门名称太长，请重新输入。');
	        return false;
   		}	
    	if(!isAllEngAndChAndNum($('#departmentID').val()))
    	{
    		$.messager.alert("系统提示",'部门编号只能是中文、字母和数字，请重新输入。');
	        return false;
    	}
    	if(isRealLength($('#departmentID').val())>64)
    	{
   			$.messager.alert("系统提示",'部门编号太长，请重新输入。');
	        return false;
   		}
   		if(!isNumber($('#staffage').val()))
   		{
   			$.messager.alert("系统提示",'年龄只能是数字，请重新输入。');
	        return false;
   		}	
	}

	function saveReader()
	{
		if(jianchageshi()===false)
		{
//			openReaderAddDialog();
			return;
		}
		$("#fm").form("submit",
		{
			url:url,
			onSubmit:function()
			{
				$("#rowidtr").val("");
				return $(this).form("validate");
			},
			success:function(result)
			{
				if(result.errorMsg)
				{
					$.messager.alert("系统提示", result.errorMsg);
					return;
				}else
				{
//					$.messager.alert("系统提示","保存成功");
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
					resetValue();									
				}
			}
		});
	}
	
	function dwqietu()
	{
		var gonghao = $("#gonghao").val();
		if(!isAllNum(gonghao))
	    {
	        $.messager.alert("系统提示",'编号只能是数字，请重新输入。');
	        return;
	    }
		var shebeihao = $("#shebeihao").val();
		var menghao = $("#menghao").val();
		var dwjson='{"action":"dwrlqietu","gonghao":"'+gonghao+'","shebeihao":"'+shebeihao+'","menghao":"'+menghao+'"}';
		$.post("../dwbrowser.php",{dwjson},function(result)
		{
			if(result.success)
			{
				$.messager.alert("系统提示","您已成功切图.");
				$("#dg").datagrid("reload");
			}else
			{
				$.messager.alert('系统提示','切图失败.  '+result.errorMsg);
			}
		},"json");
		$.messager.alert("系统提示",'正在切图，请稍候5分钟......');
	}

	function openfileuploadDialog()
	{
		
		$("#dlg_upload").dialog("open").dialog("setTitle","选择上传文件");
		
		url="uploadfile";		
	}	
	
	
	function closeuploadDialog()
	{
		$("#dlg_upload").dialog("close");
	}
	
	
	function uploadfile()
	{
		
		$("#fm_upload").form("submit",
		{
			url:url,
			onSubmit:function()
			{
				return $(this).form("validate");
			},
			success:function(result)
			{
				if(result.errorMsg)
				{
					$.messager.alert("系统提示",result.errorMsg);
					return;
				}else
				{
					$.messager.alert("系统提示","操作完成");
					$("#dlg_upload").dialog("close");
				}
			}
		});
	}
	
	
	function getCardid()
	{
		return $("#cardid").val();
	}
	
	
	function formatImg(val, row) 
	{
//		return '<img src=../class/' + row.picfilename + '>';
		return '<a href="../pshow.php?picfilename=./class/'+row.picfilename+'">'+row.picfilename+'<\a>';
//		return '<a href="../class/'+row.picfilename+'"><\a>';		
	}
	
	function ajaxGetControlerNum()
	{
	    $.ajax
		({
	        url: "/dwbrowser.php",
	        type: "POST",
	        timeout: 180000,
	        data: "{\"action\":\"dwgetcontrolernum\"}",
	        dataType: "text",
	//			async: true,
	        error: function()
			{
			    $('#massage_text').text('网络错误。'); 
	            return false;
	        },
	        complete: function()
			{              
	            if (status === 'timeout')
				{
	                $('#massage_text').text('超时。');
					this.abort();
	            }
	        },
	        success: function(deReturn)
			{
	            var DcSelection_element = document.getElementById("controlerNum");
	            var DcSelection_elementqt = document.getElementById("shebeihao");
	            var dcSelectiontab =jQuery.parseJSON(deReturn); 
	//            alert("nrows:"+dcSelectiontab.nrows+" 1:"+dcSelectiontab['s1_0']+" 7:"+dcSelectiontab['s7_0']);			
				for(var i=1;i<=dcSelectiontab.nrows;i++)
	            {
					DcSelection_element.options[i-1] = new Option(dcSelectiontab['s'+i+'_0'], dcSelectiontab['s'+i+'_0']);
					DcSelection_elementqt.options[i-1] = new Option(dcSelectiontab['s'+i+'_0'], dcSelectiontab['s'+i+'_0']);
				}			
		    }
	    });	
	}
	function dwgetstaffnum()
	{
	    $.ajax
		({
	        url: "/dwbrowser.php",
	        type: "POST",
	        timeout: 180000,
	        data: "{\"action\":\"dwgetstaffnum\"}",
	        dataType: "text",
	//			async: true,
	        error: function()
			{
			    $('#massage_text').text('网络错误。'); 
	            return false;
	        },
	        complete: function()
			{              
	            if (status === 'timeout')
				{
	                $('#massage_text').text('超时。');
					this.abort();
	            }
	        },
	        success: function(deReturn)
			{
	            var staffnumtab =jQuery.parseJSON(deReturn);
				var maxskid = 	staffnumtab["maxskid"];
//	            alert("maxskid:"+maxskid);
				if(maxskid)
				{
//					$("#staffnum").val() = String.valueOf(parseInt(maxskid)+1);
					document.getElementById("staffnum").value = parseInt(maxskid)+1;
					document.getElementById("gonghao").value = parseInt(maxskid)+1;
//					document.getElementById("staffnum_4").value = parseInt(maxskid)+1;
	//				alert("value:"+document.getElementById("staffnum").value);
				}
			}
	    });	
	}
	function datevalue()
	{
	    var currentTime = new Date();
	    var month = currentTime.getMonth() + 1;
		var day = currentTime.getDate();
		var year = currentTime.getFullYear();
		if(month < 10)
			var month_str = "0" + month;
		else
			month_str = ""+month;

		if(day < 10)
			var day_str = "0" + day;
		else
			day_str = day;
		var datestr=year+'-'+month_str+'-'+day_str + " 00:00:00";
		var date = year+10+'-'+month_str+'-'+day_str + " 23:59:59";;
//		document.getElementById('periodofvalitystart').value = datestr;
//		document.getElementById('periodofvalityend').value = date;
		$("#periodofvalitystart").datetimebox('setValue',datestr);
		$("#periodofvalityend").datetimebox('setValue',date);
	}
	$(document).ready(function()
	{
		ajaxGetControlerNum();
		dwgetstaffnum();
		datevalue();
/*	//	dwgetdepart();
		$('#gateNum_2').customSelectForm({index:3});
		$('#staff_gender_2').customSelectForm({index:2});
	//        $('#controlerNum').customSelectForm({index:1});		
		$('#periodofvalitystart_2').datetimepicker
		({
			showSecond: true,
			showMillisec: false,
			timeFormat: 'hh:mm:ss'
		});
		$('#periodofvalityend_2').datetimepicker
		({
			showSecond: true,
			showMillisec: false,
			hour: 23,
			minute: 59,
			second: 59,
			timeFormat: 'hh:mm:ss'
		});*/
	});	
</script>

</head>

<body>

	<table id="dg" title="出入园人员信息表" class="easyui-datagrid" fitColumns="false"
	 pagination="true" rownumbers="true" url="/class/readerList.php" fit="true" toolbar="#toolbar">
		<thead>
			<tr>
			    <th field="checkbox" checkbox="true"></th>
				<th field="rowid" width="50">序号</th>
				<th field="staffnum" width="100">工号</th>									
				<th field="staffname" width="100">姓名</th>
				<th field="cardnum" width="100">卡号</th>
				<th field="departmentname" width="100">部门</th>
				<th field="departmentID" width="100">部门编号</th>
				<th field="controlerNum" width="100">设备号</th>
				<th field="gatenum" width="50">闸号</th>				
				<th field="periodofvalitystart" width="100">有效期起始</th>
				<th field="periodofvalityend" width="100">有效期结束</th>
				<th field="staffgender" width="50">性别</th>	
				<th field="staffage" width="50">年龄</th>
				<th field="picfilename" data-options="formatter:formatImg" width="100">图片文件</th>

				<!--<th field="readerid" width="100">人员ID</th>						
				<th field="type" width="50">类型</th>
				<th field="gatenumber" width="50">门号</th>				
				<th field="imagefile2" width="100">图片文件2</th>
				<th field="imagefile3" width="100">图片文件3</th>								
				<th field="entrancevalidstart" width="100">入口有效期起始</th>
				<th field="entrancevalidend" width="100">入口有效期结束</th>				
				<th field="leavevalidstart" width="100">出口有效期起始</th>
				<th field="leavevalidend" width="100">出口有效期结束</th>
				<th field="imageurl" data-options="formatter:formatImg" width="200" >图片</th>-->	
			</tr>
		</thead>
	</table>
	
	<div id="toolbar">
		<div>
		
			<a href="javascript:openReaderAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
			<a href="javascript:openReaderModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
			<a href="javascript:deleteReader()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="javascript:openReaderQietuDialog()" class="easyui-linkbutton" iconCls="icon-mini-add" plain="true">切图</a>
			
		</div>
		
		<div>
			&nbsp;序号：&nbsp;<input type="text" name="s_rowId" id="s_rowId" size="15"/>
		    <!--&nbsp;读者姓名：&nbsp;<input type="text" name="s_readerName" id="s_readerName" size="15"/>
		    &nbsp;部门：&nbsp;<input type="text" name="s_departmentName" id="s_departmentName" size="15"/>-->
		    <a href="javascript:searchReader()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
		</div>
		
	</div>	
	
	
	<div id="dlg" class="easyui-dialog" style="width: 400px;height: 450px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		
		<form id="fm" method="post" enctype="multipart/form-data">
	 	    <table>
				<tr id="rowidtr">
					<td>序号：</td>
					<td><input type="text" name="rowid" id="rowid" class="easyui-validatebox"/></td>
				</tr>
				<tr>
					<td>工号：</td>
					<td><input type="text" name="staffnum" id="staffnum" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>姓名：</td>
					<td><input type="text" name="staffname" id="staffname" class="easyui-validatebox" required="true"/></td>
				</tr>				
				<tr>
					<td>卡号：</td>
					<td><input type="text" name="cardnum" id="cardnum" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>部门：</td>
					<td><input type="text" name="departmentname" id="departmentname" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>部门编号：</td>
					<td><input type="text" name="departmentID" id="departmentID" class="easyui-validatebox" required="true"/></td>
				</tr>				
				<tr>
					<td>设备号：</td>
					<!--<td><input type="text" name="controlerNum" id="controlerNum" value="ALL" class="easyui-validatebox" required="true"/></td>-->
					<td>
						<select name="controlerNum" id="controlerNum" class="easyui-validatebox">                               
                                  <!--<added by initValue>-->	 
                        </select>
                    </td>
				</tr>
				<tr>
					<td>闸号：</td>
					<!--<td><input type="text" name="gatenum" id="gatenum" value="all" class="easyui-validatebox" required="true"/></td>-->
					<td>
					    <select id="gatenum" name="gatenum" class="easyui-validatebox">
                            <option value="all" selected="selected">全部闸</option>
                            <option value="0">一号闸</option>
                            <option value="1">二号闸</option>
                            <option value="2">三号闸</option>
                            <option value="3">四号闸</option>
                        </select>
                    </td>    
				</tr>
				<tr>
					<td>有效时间起始：</td>
					<td><input class="easyui-datetimebox" editable="false" name="periodofvalitystart" id="periodofvalitystart" class="easyui-validatebox" required="true" /></td>
				</tr>
									
				<tr>
					<td>有效时间结束：</td>
					<td><input class="easyui-datetimebox" editable="false" name="periodofvalityend" id="periodofvalityend" class="easyui-validatebox" required="true"/></td>
				</tr>	
							
				<tr>
					<td>性别：</td>
					<!--<td><input type="text" name="staffgender" id="staffgender" value="男" class="easyui-validatebox"/>
					</td>-->
					<td>
						<select id="staffgender" name="staffgender" class="easyui-validatebox">
                            <option selected="selected">男</option>
                            <option>女</option>
                        </select>
                    </td>    
				</tr>	
					
				<tr>
					<td>年龄：</td>
					<td><input type="text" name="staffage" id="staffage" value="18" class="easyui-validatebox"/></td>
				</tr>	
					
				<!--<tr>
					<td>出口有效时间起始：</td>
					<td><input class="easyui-timespinner" name="leavevalidstart" id="leavevalidstart"  value="00:00:00" editable="false" showSeconds="true" class="easyui-validatebox"  required="true"/></td>
				</tr>	
					
				<tr>
					<td>出口有效时间结束：</td>
					<td><input class="easyui-timespinner" name="leavevalidend" id="leavevalidend" value="23:59:59" editable="false" showSeconds="true" class="easyui-validatebox" required="true"/></td>
				</tr>-->
				
				<tr>
					<td>人像图片</td>
					<td><input class="easyui-filebox" name="imagefile" id="imagefile"  data-options="buttonText:'选择文件', prompt:'选择文件', accept:'image/*' "/></td>
				</tr>
				
				<!--<tr>
					<td>人像图片2</td>
					<td><input class="easyui-filebox" name="imagefile2" id="imagefile2"  data-options="buttonText:'选择文件', prompt:'选择文件', accept:'image/*' " /></td>
				</tr>
				
                <tr>
					<td>人像图片3</td>
					<td><input class="easyui-filebox" name="imagefile3" id="imagefile3"  data-options="buttonText:'选择文件', prompt:'选择文件', accept:'image/*' " /></td>
				</tr>-->				
			</table>	        
		</form>
			    
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:saveReader()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:closeReaderDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
		<!--&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:dwqietu()" class="easyui-linkbutton" iconCls="icon-cut">切图</a>-->
	</div>
    
    <div id="dlgqt" class="easyui-dialog" style="width: 400px;height: 300px;padding: 10px 20px"
		closed="true" buttons="#dlg-buttons">
		
		<form id="fm" method="post">
	 	    <table>
				<tr>
					<td>工号：</td>
					<td><input type="text" name="gonghao" id="gonghao" class="easyui-validatebox" required="true"/></td>
				</tr>
				<tr>
					<td>设备号：</td>
					<td>
						<select name="shebeihao" id="shebeihao" class="easyui-validatebox">                               
                                  <!--<added by initValue>-->	 
                        </select>
                    </td>
				</tr>
				<tr>
					<td>闸号：</td>
					<td>
					    <select id="menghao" name="menghao" class="easyui-validatebox">
                            <!--<option value="all" selected="selected">全部闸</option>-->
                            <option value="0">一号闸</option>
                            <option value="1">二号闸</option>
                            <option value="2">三号闸</option>
                            <option value="3">四号闸</option>
                        </select>
                    </td>    
				</tr>
			</table>	        
		</form>		    
	</div>
	<div id="dlg-buttons">
		<a href="javascript:dwqietu()" class="easyui-linkbutton" iconCls="icon-cut">切图</a>
	</div>	

	<div id="dlg_upload" class="easyui-dialog" style="width: 400px;height: 350px;padding: 10px 20px"
		closed="true" buttons="#dlg_upload-buttons">
		
		<form id="fm_upload" method="post">
		    <table>
		    
				<tr>
					<td>上传文件：</td>
					<td><input class="easyui-filebox" name="uploaddatafile" id="uploaddatafile"  data-options="buttonText:'选择文件', prompt:'选择文件' " required="true" /></td>
				</tr>
			
			</table>
	        
		</form>
		
	</div>
    
   	<div id="dlg_upload-buttons">
		<a href="javascript:uploadfile()" class="easyui-linkbutton" iconCls="icon-ok">上传</a>
		<a href="javascript:closeuploadDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>
    
</body>

</html>
